﻿var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddRazorComponents()
                .AddInteractiveServerComponents();
builder.Services.AddApplication(option =>
{
    option.App.WebRoot = builder.Environment.WebRootPath;
    option.App.ContentRoot = builder.Environment.ContentRootPath;
    option.Database = db =>
    {
        var connString = builder.Configuration.GetSection("ConnString").Get<string>();
        db.AddSQLite<Microsoft.Data.Sqlite.SqliteFactory>(connString);
    };
});
// 如下为EFCore配置，若开启，请注释上面框架自带的连接配置
//builder.Services.AddKnownCMSEntityFramework(config =>
//{
//    config.ConnString = builder.Configuration.GetSection("ConnString").Get<string>();
//});

var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Error", true);
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseAntiforgery();
app.UseApplication();
app.MapControllers();
app.MapRazorComponents<App>()
   .AddInteractiveServerRenderMode()
   .AddAdditionalAssemblies([.. Config.Assemblies]);
app.Run();